setwd("D:/ClassificationR")


titanic2class = data_titanic[sample(nrow(data_titanic), (nrow(data_titanic))),]

yes = titanic2class[which(titanic2class$Survived == "Yes"),]
no = titanic2class[which(titanic2class$Survived == "No"),]

#part 1
titanic2class.test.1 = rbind(yes[1:142,], no[1:298,])
titanic2class.train.1 = rbind(yes[143:711,], no[299:1490,])
write.csv(titanic2class.test.1, "titanic2class.test.1.csv", row.names = FALSE)
write.csv(titanic2class.train.1, "titanic2class.train.1.csv", row.names = FALSE)

#part 2
titanic2class.test.2 = rbind(yes[143:284,], no[299:596,])
titanic2class.train.2 = rbind(yes[c(1:142,285:711),], no[c(1:298,597:1490),])
write.csv(titanic2class.test.2, "titanic2class.test.2.csv", row.names = FALSE)
write.csv(titanic2class.train.2, "titanic2class.train.2.csv", row.names = FALSE)

#part 3
titanic2class.test.3 = rbind(yes[285:426,], no[597:894,])
titanic2class.train.3 = rbind(yes[c(1:284,427:711),], no[c(1:598,895:1490),])
write.csv(titanic2class.test.3, "titanic2class.test.3.csv", row.names = FALSE)
write.csv(titanic2class.train.3, "titanic2class.train.3.csv", row.names = FALSE)

#part 4
titanic2class.test.4 = rbind(yes[427:568,], no[895:1192,])
titanic2class.train.4 = rbind(yes[c(1:426,569:711),], no[c(1:894,1193:1490),])
write.csv(titanic2class.test.4, "titanic2class.test.4.csv", row.names = FALSE)
write.csv(titanic2class.train.4, "titanic2class.train.4.csv", row.names = FALSE)

#part 5
titanic2class.test.5 = rbind(yes[569:711,], no[1193:1490,])
titanic2class.train.5 = rbind(yes[1:568,], no[1:1192,])
write.csv(titanic2class.test.5, "titanic2class.test.5.csv", row.names = FALSE)
write.csv(titanic2class.train.5, "titanic2class.train.5.csv", row.names = FALSE)
